/**
 ****************************************************************************************************
 * @file        my_2D_test.c
 * @author      嵌入式小书虫
 * @version     V1.0
 * @date        2020-04-17
 * @brief       my2d测试程序
 ****************************************************************************************************
 *
 * 修改说明
 * V1.0 20200417
 * 第一次发布
 <欢迎关注微信公众号：嵌入式小书虫>
 *
 ****************************************************************************************************
 */
#include "my_2D_test.h"
#include "my_2D_draw.h"
 
extern const my2d_tile_t c_tileic02GRAY8;
my2d_region_t s_tDirtyRegions[4] = {
    {
        .tLocation = {
            .iX = 10,
            .iY = 20,
        },
        .tSize = {
            .iWidth = 300,
            .iHeight = 10,
        },
    },
    {
        .tLocation = {
            .iX = 30,
            .iY = 50,
        },
        .tSize = {
            .iWidth = 30,
            .iHeight = 30,
        },
    },
    {
        .tLocation = {
            .iX = 70,
            .iY = 50,
        },
        .tSize = {
            .iWidth = 30,
            .iHeight = 30,
        },
    },
    {
        .tLocation = {
            .iX = 1,
            .iY = 1,
        },
        .tSize = {
            .iWidth = 30,
            .iHeight = 24,
        },
    },
    
}; 


//===============================================================
void __on_disp_adapter_load(struct my2D_scene *ptScene){

}
static int16_t time = 0;
void __on_disp_adapter_frame_start(struct my2D_scene *ptScene){
    time++;
    if(time > 300){
        time = 0;
    }
}
extern const my2d_tile_t c_tileic01RGB565;
my2d_fsm_rt_t __pfb_draw_my_disp_adapter_handler( 
                                          //void *pTarget,
                                          //const my2d_tile_t *ptTile,
                                          bool bIsNewFrame){
    //my2d_op_fill_cl_t ptOP; 
                                              
    my2d_fill_colour(NULL, MY2D_GLCD_COLOR_BLUE);
    //my2d_fill_colour(NULL, 0xffff);                                          
                                              
    do{
        my2d_region_t my_region;
        my_region.tLocation.iX = 10  + time;
        my_region.tLocation.iY = 20;
        my_region.tSize.iWidth = 10;
        my_region.tSize.iHeight = 10;
        my2d_fill_colour(//&ptOP,
                        //ptTile, 
                        &my_region, MY2D_GLCD_COLOR_RED);
        
        my_region.tLocation.iX = 30;
        my_region.tLocation.iY = 50;
        my_region.tSize.iWidth = 30;
        my_region.tSize.iHeight = 30;
         my2dp_rgb16_tile_copy_only(  //my2d_op_cp_t *ptOP,
                                            &c_tileic01RGB565,
                                            //ptTile,
                                            &my_region); 
        
        my2d_rgb565_fill_colour_with_opacity( 
                                               
                                                 &my_region,
                                               MY2D_GLCD_COLOR_RED,
                                                3);
        my_region.tLocation.iX = 70;
      my2dp_rgb16_tile_copy_keing  (  //my2d_op_cp_t *ptOP,
                                            &c_tileic01RGB565,
                                            //ptTile,
                                            &my_region,0); 
        my2d_rgb565_fill_colour_with_opacity( 
                                               
                                                 &my_region,
                                               MY2D_GLCD_COLOR_RED,
                                                1); 
        my_region.tLocation.iX = 10;
        my_region.tLocation.iY = 90;
        my_region.tSize.iWidth = 30;
        my_region.tSize.iHeight = 30;                                        
        my2dp_rgb16_tile_copy_keing_Y_mirror_image(&c_tileic01RGB565,
                                            //ptTile,
                                            &my_region,0); 
        
        my_region.tLocation.iX = 50;
        my2dp_rgb16_tile_copy_keing_X_mirror_image(&c_tileic01RGB565,
                                            //ptTile,
                                            &my_region,0); 
        my_region.tLocation.iX = 90;                                    
        my2dp_rgb16_tile_copy_keing_XY_mirror_image(&c_tileic01RGB565,
                                            //ptTile,
                                            &my_region,0);  
         my_region.tSize.iHeight = 15;                                    
         my2d_rgb565_fill_colour_with_opacity(                                               
                                                 &my_region,
                                               0,
                                                100);                                    

        my_region.tLocation.iX = 10;
        my_region.tLocation.iY = 130;
        my_region.tSize.iWidth = 30;
        my_region.tSize.iHeight = 30; 
        my2dp_rgb16_tile_copy_only_and_opacity(&c_tileic01RGB565,
                                            
                                            &my_region,
                                            100); 
        my_region.tLocation.iX = 50;                                    
        my2dp_rgb16_tile_copy_keing_and_opacity(&c_tileic01RGB565,                                           
                                            &my_region,
                                            0,
                                            4); 
                                            
        my_region.tLocation.iX = 10;
        my_region.tLocation.iY = 170;
        my_region.tSize.iWidth = 30;
        my_region.tSize.iHeight = 30; 
        my2d_fill_colour_with_mask(&c_tileic02GRAY8,                                            
                                                &my_region,
                                                0xffff);  
        my2d_set_lcd_text_font(my2D_FONT_16x24);
        //my2d_set_lcd_text_font(my2D_FONT_6x8);
        my2d_lcd_text_location(1, 1);
        my2d_lcd_printf("abcdef");
        
        my2d_set_lcd_text_font(my2D_FONT_6x8);
        my2d_lcd_text_location(38, 10);
        my2d_lcd_printf("abcdef");
    }while(0);                                          
    return my2D_fsm_rt_on_going;                                            
}

my2D_scene_t *__my2d_disp_adapter_init(my2D_scene_t* ptThis){
    /**ptThis = {
        .fnOnLoad =  &__on_scene1_load,
    };*/
    ptThis->fnOnLoad =  &__on_disp_adapter_load;
    ptThis->fnScene  = &__pfb_draw_my_disp_adapter_handler;
    ptThis->fnOnFrameStart = &__on_disp_adapter_frame_start;
#if DIRTY_REGIONS_ENABLE       
    my_2D_op.DirtyRegions_num = 4;
    my_2D_op.ptDirtyRegions = s_tDirtyRegions;
#endif    
    return ptThis;
}


//=====================================================
